#include <algorithm>
#include <cstdio>
#include <cstring>

const int N = 10005;
int n, t, f[21][N], dep[N], dis[N];
int e_cnt, heads[N];
char opt[5];

struct Edge {
  int v, nxt, w;
} e[N << 1];

inline void add(int u, int v, int w) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt, e[e_cnt].w = w;
}

void dfs(int x) {
  for (int i = heads[x], v; i; i = e[i].nxt) {
    if ((v = e[i].v) != f[0][x]) {
      f[0][v] = x;
      dep[v] = dep[x] + 1;
      dis[v] = dis[x] + e[i].w;
      dfs(v);
    }
  }
}

inline int LCA(int x, int y) {
  if (dep[x] < dep[y]) std::swap(x, y);
  for (int i = 20; ~i; --i) {
    if (dep[f[i][x]] >= dep[y]) x = f[i][x];
  }
  if (x == y) return x;
  for (int i = 20; ~i; --i) {
    if (f[i][x] != f[i][y]) x = f[i][x], y = f[i][y];
  }
  return f[0][x];
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
  freopen("SP913 QTREE2.in", "r", stdin);
  freopen("SP913 QTREE2.out", "w", stdout);
#endif
#endif

  scanf("%d", &t);
  while (t--) {
    memset(heads, 0, sizeof(heads));
    e_cnt = 0;
    scanf("%d", &n);
    int a, b, c;
    for (int i = 1; i < n; ++i) {
      scanf("%d%d%d", &a, &b, &c);
      add(a, b, c), add(b, a, c);
    }
    dep[1] = 1, f[0][1] = 1, dfs(1);
    for (int i = 1; i < 21; ++i) {
      for (int j = 1; j <= n; ++j) {
        f[i][j] = f[i - 1][f[i - 1][j]];
      }
    }
    while (true) {
      scanf("%s", opt);
      if (opt[0] == 'D' && opt[1] == 'O') break;
      if (opt[0] == 'D') {
        scanf("%d%d", &a, &b);
        printf("%d\n", dis[a] + dis[b] - (dis[LCA(a, b)] << 1));
      } else {
        scanf("%d%d%d", &a, &b, &c);
        int mlca = LCA(a, b), tmp;
        if (dep[a] - dep[mlca] + 1 >= c) {
          tmp = dep[a] - c + 1;
          for (int i = 20; ~i; --i) {
            if (dep[f[i][a]] >= tmp) a = f[i][a];
          }
          printf("%d\n", a);
        } else {
          tmp = dep[mlca] + c - (dep[a] - dep[mlca] + 1);
          for (int i = 20; ~i; --i) {
            if (dep[f[i][b]] >= tmp) b = f[i][b];
          }
          printf("%d\n", b);
        }
      }
    }
  }
  return 0;
}